package com.xbongbong.pro.rabbitmq.producer.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.rabbitmq.binders.ScoreProducerBinder;
import com.xbongbong.pro.rabbitmq.producer.ScoreProducer;
import com.xbongbong.pro.score.pojo.dto.ScoreRabbitMqDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.context.annotation.Lazy;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 评分 生产者
 * @author chunyang.qin
 * @date 2020/12/7 20:32
 * @since v4.3.2.3
 * @version v4.3.2.3
 */
@Service("scoreProducer")
@EnableBinding({ScoreProducerBinder.class})
public class ScoreProducerImpl implements ScoreProducer {
    private static final Logger LOG = LoggerFactory.getLogger(ScoreProducerImpl.class);
    @Resource
    @Lazy
    private ScoreProducerBinder scoreProducerBinder;


    @Override
    public void sendMessage(ScoreRabbitMqDTO message){
        try {
            LOG.info("ScoreProducer 发送评分消息，message-{}",message.toString());
            MessageBuilder messageBuilder = MessageBuilder.withPayload(message);
            scoreProducerBinder.scoreOutput().send(messageBuilder.build());
        } catch (Exception e) {
            LOG.error("score message fail：", e);
        }
    }
}
